package com.vcourse.service.base.exception;

import com.vcourse.commons.result.ResultCodeEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author Zengsh123
 * @date 2020-05-29 21:50
 * 通用自定义异常
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class CustomException extends RuntimeException {
    private static final long serialVersionUID = 1602067865672821974L;
    private Integer code;

    public CustomException(String message, Integer code) {
        super(message);
        this.code = code;
    }

    public CustomException(ResultCodeEnum resultCodeEnum) {
        super(resultCodeEnum.getMessage());
        this.code = resultCodeEnum.getCode();
    }

    @Override
    public String toString() {
        return "CustomException{" +
                "code=" + code + ", message=" + this.getMessage() +
                '}';
    }
}
